package com.xuhai.blog.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xuhai.blog.admin.entity.BannerEntity;
import com.xuhai.blog.admin.mapper.BannerMapper;
import com.xuhai.blog.admin.service.BannerService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 轮播/外部链接表 服务实现类
 * </p>
 *
 * @author 机蜂
 * @since 2022-02-08
 */
@Service
public class BannerServiceImpl extends ServiceImpl<BannerMapper, BannerEntity> implements BannerService {

    @Override
    public IPage<BannerEntity> getPage(int page, int limit, BannerEntity banner) {
        IPage<BannerEntity> iPage=this.page(new Page<>(page,limit)
                ,new QueryWrapper<BannerEntity>()
                        .eq("type",banner.getType())
                        .eq(banner.getStatus()!=null,"status",banner.getStatus())
                        .eq(StringUtils.isNotBlank(banner.getBannerName()),"banner_name",banner.getBannerName())
                        .orderByDesc("banner_id")
        );
        return iPage;
    }

    @Override
    public List<BannerEntity> getBannerList() {
        return this.list(new QueryWrapper<BannerEntity>().eq("type",1).eq("status",1));
    }

    @Override
    public List<BannerEntity> getHrefList() {
        return this.list(new QueryWrapper<BannerEntity>().eq("type",2).eq("status",1));
    }
}
